package com.jjc.android.fragment

import android.content.Intent
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.hjq.toast.ToastUtils
import com.jjc.android.Constants
import com.jjc.android.GlobalManager
import com.jjc.android.R
import com.jjc.android.UserManager
import com.jjc.android.activity.*
import com.jjc.android.base.BaseLazyLoadFragment
import com.jjc.android.util.UIStatusBarHelper
import com.jjc.android.view.onClick

class MineFragment : BaseLazyLoadFragment() {

    companion object{
        fun newInstance():MineFragment{
            val fragment = MineFragment()
            fragment.setInflateLazy(true)
            return fragment
        }
    }

    private lateinit var serverBtn: TextView
    private lateinit var feedbackBtn: TextView
    private lateinit var problemBtn: TextView
    private lateinit var testerBtn: TextView
    private lateinit var myBookBtn: TextView
    private lateinit var myDeviceBtn: TextView
    private lateinit var userTopLayout: LinearLayout
    private lateinit var settingBtn: ImageView
    private lateinit var userNameTxt: TextView
    private lateinit var userHeadImg: ImageView

    private var iconClickCount = 0

    override fun getLayoutId(): Int = R.layout.fragment_mine

    override fun initView(view: View) {
        super.initView(view)
        initViews(view)
        UIStatusBarHelper.setStatusBarPadding(userTopLayout)
        settingBtn.onClick {
            startActivity(Intent(requireContext(),SettingActivity::class.java))
        }
        feedbackBtn.onClick {
            startActivity(Intent(requireContext(),FeedBackActivity::class.java))
        }
        testerBtn.onClick {
            startActivity(Intent(requireContext(),TestedPersonListActivity::class.java))
        }
        myBookBtn.onClick {
            startActivity(Intent(requireContext(),ProductManualActivity::class.java))
        }
        problemBtn.onClick {
            startActivity(Intent(requireContext(),CommonQuestionActivity::class.java))
        }
        myDeviceBtn.onClick {
            startActivity(Intent(requireContext(),MyDeviceActivity::class.java))
        }
        serverBtn.onClick {
            BrowserActivity.start(requireContext(), url = Constants.ONLINE_SERVER, title = getString(R.string.online_server_txt))
        }
        userHeadImg.setOnClickListener {
            iconClickCount++
            if(iconClickCount%5==0){
                GlobalManager.isShowDebugInfo = !GlobalManager.isShowDebugInfo
                ToastUtils.show("调试信息已切换至："+(if(GlobalManager.isShowDebugInfo) "显示" else "隐藏"))
            }
        }
        userNameTxt.text = UserManager.userInfo().tuoTuUserName
    }

    private fun initViews(view: View) {
        userHeadImg = view.findViewById(R.id.userHeadImg)
        userNameTxt = view.findViewById(R.id.userNameTxt)
        settingBtn = view.findViewById(R.id.settingBtn)
        userTopLayout = view.findViewById(R.id.userTopLayout)
        myDeviceBtn = view.findViewById(R.id.myDeviceBtn)
        myBookBtn = view.findViewById(R.id.myBookBtn)
        testerBtn = view.findViewById(R.id.testerBtn)
        problemBtn = view.findViewById(R.id.problemBtn)
        feedbackBtn = view.findViewById(R.id.feedbackBtn)
        serverBtn = view.findViewById(R.id.serverBtn)
    }
}